package com.xzq.wanandroid.presenter.home;

import com.xzq.wanandroid.base.presenter.BasePresenter;
import com.xzq.wanandroid.bean.db.Banner;
import com.xzq.wanandroid.contract.home.HomeContract;
import com.xzq.wanandroid.model.HomeModel;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class HomePresenter extends BasePresenter<HomeContract.IHomeView> implements HomeContract.IHomePresenter {

    HomeContract.IHomeModel iHomeModel;

    public HomePresenter() {
        iHomeModel = new HomeModel();
    }

    @Override
    public void loadBanner() {
        iHomeModel.loadBanner().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<Banner>>() {
                    @Override
                    public void onSubscribe(@NotNull Disposable d) {
                        compositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(@NotNull List<Banner> banners) {
                        if (isViewAttached()) {
                            getView().loadBanner(banners);
                        }
                    }

                    @Override
                    public void onError(@NotNull Throwable e) {
                        if (isViewAttached()) {
                            getView().onLoadFailed();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    public void refreshBanner() {

    }

    @Override
    public void loadArtical(int pagenum) {

    }

    @Override
    public void refreshArtical(int pagenum) {

    }

    @Override
    public void collect(int articleId) {

    }

    @Override
    public void unCollect(int articleId) {

    }
}
